package org.netty.push.server;

import org.netty.push.core.proto.codec.CodecFactory;
import org.netty.push.core.proto.handler.MessageHandlerManager;
import org.netty.push.server.message.HandlerManagerFactory;
import org.netty.push.utils.ApplicationContextHolder;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * 初始化管道处理器，添加自定义的处理器
 * @author zzh
 *
 */
public class CustomerChannelInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();
		
		pipeline.addLast(CodecFactory.buildDecoder());
		pipeline.addLast(CodecFactory.buildEncoder());
		MessageHandlerManager messageHandlerManager=ApplicationContextHolder.getApplicationContext().getBean(MessageHandlerManager.class);
		pipeline.addLast(new CustomerHandler(messageHandlerManager));
	}

}
